package com.chuanyang.driverh.mainorder;


import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.Polygon;
import com.amap.api.maps.model.PolygonOptions;
import com.chuanyang.driverh.R;
import com.chuanyang.driverh.responseresult.CarCurrentStatusData;
import com.chuanyang.driverh.responseresult.LoadUnloadGuideData;
import com.chuanyang.driverh.responseresult.LoadUnloadGuideStateResult;
import com.chuanyang.driverh.responseresult.SelWebWaybillWizardData;
import com.chuanyang.driverh.utils.BitmapUtil;
import com.chuanyang.driverh.utils.ConstUtil;
import com.chuanyang.driverh.utils.DialogUtil;
import com.chuanyang.driverh.utils.JsonUtil;
import com.chuanyang.driverh.utils.LogUtils;
import com.chuanyang.driverh.utils.PrintUtil;
import com.chuanyang.driverh.utils.SharedPrefUtil;
import com.chuanyang.driverh.utils.WindowUtils;
import com.chuanyang.driverh.utils.eventbus.LocatinStateEvent;
import com.chuanyang.driverh.utils.net.JsonGenericsSerializator;
import com.chuanyang.driverh.utils.net.MyCallback;
import com.chuanyang.driverh.utils.net.MyHttpUtil;
import com.chuanyang.driverh.utils.net.MyStringCallback;
import com.chuanyang.driverh.utils.widget.photoview.PhotoView;
import com.chuanyang.driverh.utils.widget.photoview.PhotoViewAttacher;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import okhttp3.Call;

public class OutFactoryActivity extends Activity implements View.OnClickListener {
    private MapView mMapView;
    private AMap aMap;
    private LatLng latlng;
    private TextView tv_outfactorymap_state;
    private TextView tv_outfactorymap_nextstate;
    private TextView tv_outfactorymap_bt;
    private Bitmap srcBitmap;
    private Bitmap alterBitmap;
    private Canvas canvas;
    private Paint paint;
    private float imageWide;
    private float visibleHeight;
    private float visivleWide;
    private float orginScaleX;
    private float orginScaleY;
    private int imageHeight;
    private double orginScale;
    private double longitudePix;
    private double startLongitude, endLongitude, startLatitude, endLatitude;//这是图片边界的经纬度
    private boolean inMapInit = false;//场内地图是否初始化
    private boolean hasArrangeLines = false;//是否已有分配路线
    private double currentScale;

    private RectF mrect;
    private LocatinStateEvent locatinStateEvent;
    private PhotoView in_map;
    private LoadUnloadGuideData loadUnloadGuideData;
    private int last_locationstate;
    private RelativeLayout rv_in_map;
    private SelWebWaybillWizardData selWebWaybillWizardData;
    private HashMap params;
    private Marker marker;
    private ImageView iv_car;
    private ImageView iv_hall;
    private int currentState;
    private AsyncTask myTask;
    private TimerTask task;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.order_act_outfactorymap);
        //获取地图控件引用
        mMapView = (MapView) findViewById(R.id.out_map);
        //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState)，实现地图生命周期管理
        mMapView.onCreate(savedInstanceState);
        initView();

    }

    private void initView() {
        //获取传递过来的装卸货向导信息
        loadUnloadGuideData = (LoadUnloadGuideData) getIntent().getSerializableExtra("loadUnloadGuideData");
        selWebWaybillWizardData = (SelWebWaybillWizardData) getIntent().getSerializableExtra("selWebWaybillWizardData");
        task = new TimerTask() {
            @Override
            public void run() {
                getLoadUnloadGuideState();
            }
        };
        myTask = new AsyncTask<String, Void, Bitmap>() {
            @Override
            protected void onPreExecute() {
                // [4]创建一个画笔
                paint = new Paint();
                //场内地图时显示
                in_map = (PhotoView) findViewById(R.id.in_map);
                iv_car = (ImageView) findViewById(R.id.iv_car);
                iv_hall = (ImageView) findViewById(R.id.iv_hall);
                rv_in_map = (RelativeLayout) findViewById(R.id.rv_in_map);
                TextView tv_left = (TextView) findViewById(R.id.base_titlebar_back);
                TextView tv_mid = (TextView) findViewById(R.id.base_titlebar_mid);
                TextView tv_right = (TextView) findViewById(R.id.base_titlebar_right);
                //当前状态
                tv_outfactorymap_state = (TextView) findViewById(R.id.tv_outfactorymap_state);
                //下个状态
                tv_outfactorymap_nextstate = (TextView) findViewById(R.id.tv_outfactorymap_nextstate);
                //右侧的按钮
                tv_outfactorymap_bt = (TextView) findViewById(R.id.tv_outfactorymap_bt);
                tv_left.setOnClickListener(OutFactoryActivity.this);
                tv_mid.setOnClickListener(OutFactoryActivity.this);
                tv_right.setOnClickListener(OutFactoryActivity.this);
                tv_outfactorymap_state.setOnClickListener(OutFactoryActivity.this);
                tv_outfactorymap_nextstate.setOnClickListener(OutFactoryActivity.this);
                tv_outfactorymap_bt.setOnClickListener(OutFactoryActivity.this);
                if (aMap == null) {
                    aMap = mMapView.getMap();
                }
            }

            @Override
            protected Bitmap doInBackground(String... params) {
                srcBitmap = BitmapUtil.compressNetDimension(params[0], OutFactoryActivity.this);
                return srcBitmap;
            }

            @Override
            protected void onPostExecute(Bitmap bitmap) {

                initInMap();
                Timer timer = new Timer();
                timer.schedule(task, 0, 30000);

            }
        };

        Object[] images = {loadUnloadGuideData.getImage()};
        myTask.execute(images);


    }

    /**
     * 没隔5秒获取一次当前的位置
     */
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (last_locationstate == 0 || locatinStateEvent.getState() != last_locationstate)//如果上次车辆的状态有变化，就去更改对应的ui
            {
                setState();

            }
            if (isInMapOrOutMap())//如果是场内
            {
                if (!inMapInit)//第一次场内地图没初始化
                {
                    initInMap();//显示场内地图

                }
                setInMapCarLocation(mrect, locatinStateEvent);//设置车辆位置

            } else {//如果在场外
                if (mMapView.getVisibility() == View.GONE) {
                    initOutMap();

                } else {

                }
                //实时的显示车辆的位置
                setVisibleCenter(locatinStateEvent.getLng(), locatinStateEvent.getLat());

            }


            //记录上次车辆的状态
            last_locationstate = locatinStateEvent.getState();

        }
    };

    /**
     * 显示场外地图，对其初始化
     */
    private void initOutMap() {
        if (inMapInit) {
            paint.setColor(Color.TRANSPARENT);
            paint.setStrokeWidth(1);
            paint.setAntiAlias(true);
        }
        mMapView.setVisibility(View.VISIBLE);
        rv_in_map.setVisibility(View.GONE);

    }

    /**
     * 显示场内地图，对其初始化，并标明车辆需要行驶的折线
     */
    private void initInMap() {
        visivleWide = WindowUtils.getScreenWide(OutFactoryActivity.this);
        visibleHeight = WindowUtils.getScreenHight(OutFactoryActivity.this) - WindowUtils.getNavigationBarHeight(OutFactoryActivity.this) - WindowUtils.getStatusHight(OutFactoryActivity.this) - (int) ((44 + 60) * WindowUtils.getPixel(OutFactoryActivity.this));
        mMapView.setVisibility(View.GONE);
        rv_in_map.setVisibility(View.VISIBLE);
        in_map.setScaleType(ImageView.ScaleType.CENTER_CROP);//按比例缩放直到填充整个屏幕
        // [2]创建一个模板
        alterBitmap = Bitmap.createBitmap(srcBitmap.getWidth(),
                srcBitmap.getHeight(), srcBitmap.getConfig());
        // [3]创建一个画布 以alterbitmap为模板创建一个画布
        canvas = new Canvas(alterBitmap);
        canvas.drawBitmap(srcBitmap, new Matrix(), paint);
        in_map.setImageBitmap(alterBitmap);
        cacluteScale();//计算出缩放比
        getFourPoint();//得到四个角的矩阵
        getLongitudePix();//计算出一个经纬度对应的屏幕像素
        in_map.setOnMatrixChangeListener(new PhotoViewAttacher.OnMatrixChangedListener() {
            @Override
            public void onMatrixChanged(RectF rect) {
                //获取当前的矩阵
                mrect = rect;
                //获取当前的缩放比
                currentScale = orginScale * in_map.getScale();
                setInMapCarLocation(mrect, locatinStateEvent);
                LogUtils.e("rect", rect.left + "----------" + rect.top + "---------" + rect.right + "-------" + rect.bottom);
                //矩阵变化时，设置当前车辆的位置
                //showMsg(rect.toString() + "-------" + in_map.getScale() + "---" + currentScale);
                // paint.setStrokeWidth(2 / photoview.getScale());
                //  photoview.setImageBitmap(alterBitmap);


            }
        });
        inMapInit = true;

    }

    private void setState() {
        if (locatinStateEvent != null) {
            switch (locatinStateEvent.getState()) {
                case 1:
                    tv_outfactorymap_state.setText("当前车辆已报到");
                    tv_outfactorymap_nextstate.setText("等待分配装车清单");//下部地图：显示高德地图，并在地图中标注想到位置与车辆位置
                    break;
                case 2:
                    tv_outfactorymap_state.setText("已分配装车清单");
                    tv_outfactorymap_nextstate.setText("等待分配线路信息");//下部地图：显示高德地图，并在地图中标注想到位置与车辆位置
                    tv_outfactorymap_bt.setVisibility(View.VISIBLE);
                    tv_outfactorymap_bt.setText("查看装车清单");
                    break;
                case 3:
                    tv_outfactorymap_state.setText("已分配线路信息");//根据地图经纬度建立围栏，由此判断车辆是否在厂内
                    //在厂内：改变地图界面（显示地图图片，取货路线，出场路线，显示仓库位置，车辆位置），显示厂内地图
                    // 在厂外：提示车辆驶出厂外，显示高德地图
                    tv_outfactorymap_nextstate.setText("请前往装货或卸货");
                    tv_outfactorymap_bt.setVisibility(View.VISIBLE);
                    tv_outfactorymap_bt.setText("查看装车清单");
                    break;
                case 4://  在厂内：显示不变；在厂外：提示车辆驶出厂外，装货向导结束，显示高德地图
                    tv_outfactorymap_state.setText("已分出库信息");
                    tv_outfactorymap_nextstate.setText("等待驶离厂区");
                    tv_outfactorymap_bt.setVisibility(View.GONE);
                    break;
                case 5://  在厂内：显示不变；在厂外：提示车辆驶出厂外，装货向导结束，显示高德地图
                    tv_outfactorymap_state.setText("卸货完成，请确认卸货信息");
                    tv_outfactorymap_nextstate.setText("运输完成");
                    tv_outfactorymap_bt.setVisibility(View.GONE);
                    tv_outfactorymap_bt.setText("运输完成");

                    break;

            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        mMapView.onDestroy();
        handler.removeMessages(1);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，实现地图生命周期管理
        mMapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，实现地图生命周期管理
        mMapView.onPause();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，实现地图生命周期管理
        mMapView.onSaveInstanceState(outState);
    }


    @Override
    public void onClick(View v) {

    }

    /**
     * 根据动画按钮状态，调用函数animateCamera或moveCamera来改变可视区域
     */
    private void changeCamera(CameraUpdate update) {

        aMap.moveCamera(update);

    }

    /**
     * 将当前位置车辆位置设置为地图的中心点，并标注出车的位置
     */
    private void setVisibleCenter(double lng, double lat) {
        latlng = new LatLng(lat, lng);
        changeCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(
                latlng, 18, 30, 0)));
        if (marker != null) {
            marker.remove();
        }
        marker = aMap.addMarker(new MarkerOptions().position(latlng)
                .icon(BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
    }

    /**
     * 并标注出仓库的位置
     */
    private void setHallLocation(double lng, double lat) {
        latlng = new LatLng(lat, lng);
        marker = aMap.addMarker(new MarkerOptions().position(latlng)
                .icon(BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_RED)));
    }
//    //绘制一条实线标注车辆的行驶轨迹  场外地图
//    private void addPolylinessoild(SelWebWaybillWizardData selWebWaybillWizardData) {
//        ArrayList<LatLng> wayLines=new ArrayList();
//        if (selWebWaybillWizardData.getOutRouteId() != null) {
//            if (selWebWaybillWizardData.getOutRouteId().getWebWizardPointList() != null && selWebWaybillWizardData.getOutRouteId().getWebWizardPointList().size() > 0) {
//                for (SelWebWaybillWizardData.OutRouteIdBean.WebWizardPointListBean webWizardPointListBean : selWebWaybillWizardData.getOutRouteId().getWebWizardPointList()) {
//                    String[] wayLatLng = webWizardPointListBean.getLngAndLat().split(",");
//                    double wayLat = Double.parseDouble(wayLatLng[0]);
//                    double wayLng = Double.parseDouble(wayLatLng[1]);
//                    LatLng way = new LatLng(wayLat, wayLng);
//                    wayLines.add(way);
//                }
//                LogUtils.e("addPolylinessoild","--------addPolylinessoild");
//                aMap.addPolyline( new PolylineOptions().addAll(wayLines).width(20).color(R.color.red));
//            }
////            LatLng A = new LatLng(11, 65);
////            LatLng B = new LatLng(12, 65.8);
////            LatLng C = new LatLng(12.1, 70);
////            LatLng D = new LatLng(12, 77.5);
////            aMap.addPolyline((new PolylineOptions())
////                    .add(A, B, C, D)
////                    .width(10)
////                    .color(Color.argb(255, 1, 1, 1)));
//        }
//    }

    /**
     * 判断车辆是在场内还是场外
     * 如果在场内返回true,否则返回false
     */
    private boolean isInMapOrOutMap() {
        if (locatinStateEvent == null) {
            return true;
        }

        LatLng carlatlng = new LatLng(locatinStateEvent.getLat(), locatinStateEvent.getLng());
        PolygonOptions options = new PolygonOptions();
        String[] latlngs = loadUnloadGuideData.getWizardPoint().split(";");
        for (String latlng : latlngs) {
            String[] latandlng = latlng.split(",");
            double lng = Double.parseDouble(latandlng[1]);
            double lat = Double.parseDouble(latandlng[0]);
            options.add(new LatLng(lat, lng));
        }
        Polygon polygon = aMap.addPolygon(options.strokeWidth(4)
                .strokeColor(R.color.green_light)
                .fillColor(R.color.red));

        return polygon.contains(carlatlng);
    }


    //-----------------------------------------------------------------------------------------------------------------------------------------------------

    /**
     * 设置场内地图的折线也就是车辆需要行驶的轨迹
     *
     * @param selWebWaybillWizardData
     */
    private void setInMapPointLines(SelWebWaybillWizardData selWebWaybillWizardData) {
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(1);
        paint.setAntiAlias(true);
        if (selWebWaybillWizardData.getInRouteId() != null) {
            if (selWebWaybillWizardData.getInRouteId().getWebWizardPointList() != null && selWebWaybillWizardData.getInRouteId().getWebWizardPointList().size() > 0) {
                List<SelWebWaybillWizardData.InRouteIdBean.WebWizardPointListBean> pointListBeanList = selWebWaybillWizardData.getInRouteId().getWebWizardPointList();

                for (int m = 0; m < pointListBeanList.size(); m++) {
                    if (m >= 2) {
                        SelWebWaybillWizardData.InRouteIdBean.WebWizardPointListBean lastWebWizardPointListBean = pointListBeanList.get(m - 1);
                        SelWebWaybillWizardData.InRouteIdBean.WebWizardPointListBean currentWebWizardPointListBean = pointListBeanList.get(m);
                        String[] lastWayLatLng = lastWebWizardPointListBean.getLngAndLat().split(",");
                        String[] currentWayLatLng = currentWebWizardPointListBean.getLngAndLat().split(",");
                        double lastWayLat = Double.parseDouble(lastWayLatLng[0]);
                        double lastWayLng = Double.parseDouble(lastWayLatLng[1]);
                        double currentWayLat = Double.parseDouble(currentWayLatLng[0]);
                        double currentWayLng = Double.parseDouble(currentWayLatLng[1]);
                        float lastLocationX = (float) (mrect.left + longitudePix * currentScale * (lastWayLng - startLongitude));
                        float lastLocationY = (float) (mrect.top + longitudePix * currentScale * (lastWayLat - startLatitude));
                        float currentLocationX = (float) (mrect.left + longitudePix * currentScale * (currentWayLng - startLongitude));
                        float currentLocationY = (float) (mrect.top + longitudePix * currentScale * (currentWayLat - startLatitude));
                        canvas.drawLine(lastLocationX, lastLocationY, currentLocationX, currentLocationY, paint);
                    }
                }


            }
        }
    }

    /**
     * 计算初始状态下图片的缩放比
     * 分析 ：为了让图片占满整个屏幕，则图片的宽高都要大于等于屏幕，其缩放比应该选较大的那个值
     */
    private void cacluteScale() {
        //获取图片的宽度
        imageWide = srcBitmap.getWidth();
        //获取图片的高度
        imageHeight = srcBitmap.getHeight();
        //获取加载时图片的缩放比
        orginScaleX = visivleWide / imageWide;
        orginScaleY = visibleHeight / imageHeight;
        LogUtils.e("orginScaleX", visivleWide + "--------" + imageWide);
        LogUtils.e("orginScaleY", visibleHeight + "--------" + imageHeight);
        orginScale = orginScaleX > orginScaleY ? orginScaleX : orginScaleY;
        currentScale = orginScale;
        LogUtils.e("currentScale", orginScale + "--------");

    }

    /**
     * 计算一个精度对应的图片的像素
     * 分析：由于将地球对应看成一个球形，1精度和1纬度对应的曲线距离近似成直线，则两者的距离是相等的
     * 而图片也是未变形的图片，则1精度对应的屏幕像素和1纬度对应的屏幕像素应该也是相等的
     */
    private void getLongitudePix() {
        //计算出图片的精度差
        double passLongitude = endLongitude - startLongitude;
        //得到1精度对应的原始图片的像素值（1纬度对应的像素值和1精度对应的像素值近似相等）
        longitudePix = imageWide / passLongitude;

    }

//    /**
//     * 通过经纬度和缩放比确定在屏幕的位置
//     */
//    private void cacluteOriginLocation(RectF rect, double longitude, double latitude) {
//        //计算出当前车辆位置距图片矩阵右下的像素值(从屏幕左上角开始，右下为正
//        locationX = (float) (rect.left + longitudePix * currentScale * (longitude - startLongitude));
//        locationY = (float) (rect.top + longitudePix * currentScale * (latitude - startLatitude));
//    }

    /**
     * 得到图片四个角所在的矩阵
     */
    private void getFourPoint() {
        ArrayList<Double> lats = new ArrayList();
        ArrayList<Double> lngs = new ArrayList();
        String[] latlngs = loadUnloadGuideData.getWizardPoint().split(";");
        for (String latlng : latlngs) {
            String[] latandlng = latlng.split(",");
            Double lat = Double.parseDouble(latandlng[0]);
            Double lng = Double.parseDouble(latandlng[1]);
            lats.add(lat);
            lngs.add(lng);


        }
        Collections.sort(lats);
        Collections.sort(lngs);
        startLatitude = lats.get(0);
        endLatitude = lats.get(lats.size() - 1);
        startLongitude = lngs.get(0);
        endLongitude = lngs.get(lngs.size() - 1);
    }

    /**
     * 显示场内地图车辆的位置
     */
    private void setInMapCarLocation(RectF rect, LocatinStateEvent locatinStateEvent) {
        if (locatinStateEvent != null) {
            locatinStateEvent.setLat(31.294559235);
            locatinStateEvent.setLng(121.48373723);
            float carlocationX = (float) (rect.left + longitudePix * currentScale * (locatinStateEvent.getLng() - startLongitude));
            float carlocationY = (float) (rect.top + longitudePix * currentScale * (locatinStateEvent.getLat() - startLatitude));
            LogUtils.e("carlocationY", carlocationY + "-------" + rect.top + "---" + longitudePix + "---" + currentScale + "---" + locatinStateEvent.getLat() + "----" + startLatitude);
            LogUtils.e("carlocationX", carlocationX + "-------" + rect.left + "---" + longitudePix + "---" + currentScale + "---" + locatinStateEvent.getLng() + "----" + startLongitude);
            iv_car.setX(carlocationX);
            iv_car.setY(carlocationY);
        }
    }

    /**
     * 显示场内地图仓库的位置
     */
    private void setInMapHallLocation(RectF rect, double longitude, double latitude) {
        float halllocationX = (float) (rect.left + longitudePix * currentScale * (longitude - startLongitude));
        float halllocationY = (float) (rect.top + longitudePix * currentScale * (latitude - startLatitude));
//        iv_car.setX(locationX);
//        iv_car.setY(locationY);

    }

    //----------------------------------------------------------------------------------------------------


    /**
     * 获取当前车辆的位置
     */
    private void getCarCurrentLocation() {
        Map<String,String> params=new HashMap<String, String>();
        params.put("CarID", "117917");
        MyHttpUtil.getCarCurrentLocation(this,params, new MyStringCallback(){
            @Override
            public void onResponse(String responseString, int id) {
                super.onResponse(responseString, id);

                try {
                    if (!TextUtils.isEmpty(responseString)) {
                        List<CarCurrentStatusData> carCurrentStatusDataList = (List<CarCurrentStatusData>) JsonUtil.parseJsonToList(responseString, new TypeToken<List<CarCurrentStatusData>>() {
                        }.getType());

                        if (carCurrentStatusDataList != null && carCurrentStatusDataList.size() > 0) {
                            if (locatinStateEvent == null) {
                                locatinStateEvent = new LocatinStateEvent();
                            }
                            locatinStateEvent.setState(currentState);
                            locatinStateEvent.setLat(carCurrentStatusDataList.get(0).getLast_lat());
                            locatinStateEvent.setLng(carCurrentStatusDataList.get(0).getLast_lon());
                           SharedPrefUtil.setLongitude(carCurrentStatusDataList.get(0).getLast_lon() + "");
                            SharedPrefUtil.setLatitude(carCurrentStatusDataList.get(0).getLast_lat() + "");
                            // handler.sendEmptyMessage(1);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


            }
        });
    }

    /**
     * 获取装卸货向导的状态
     */
    private void getLoadUnloadGuideState() {
        DialogUtil.showLoadingDialog(this,"加载中...");
        Map<String,String> params=new HashMap<String, String>();
        params.put("waybillId", 1314 + "");
        params.put("wizardId", 3 + "");
        MyHttpUtil.getLoadUnloadGuideState(this,params, new MyCallback<LoadUnloadGuideStateResult>(this,new JsonGenericsSerializator()) {
            @Override
            public void onFail(Call call, Exception e, int id) {
                e.printStackTrace();
                PrintUtil.toast(OutFactoryActivity.this, "网络异常，请稍后再试");
            }
            @Override
            public void onSuccess(LoadUnloadGuideStateResult result, int id) {
                if (result.getCode() == ConstUtil.OK) {
                    currentState = result.getData().getState();
                    getCarCurrentLocation();
                }else{
                    PrintUtil.toast(OutFactoryActivity.this,result.getMsg());
                }
            }
        });


    }
}
